<!DOCTYPE html>
<html>
<head>
    <title>Kanderon</title>
    <meta http-equiv='Content-Type' content='text/html;charset=utf-8' >
    <link href='/style.css' rel='stylesheet' type='text/css'>
</head>
<body>
    <div class="header">
        &nbsp;&nbsp;_&nbsp;&nbsp;__&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_<br>
        &nbsp;|&nbsp;|/&nbsp;/___&nbsp;&nbsp;__&nbsp;_&nbsp;_&nbsp;__&nbsp;&nbsp;&nbsp;__|&nbsp;|&nbsp;___&nbsp;_&nbsp;__&nbsp;___&nbsp;&nbsp;_&nbsp;__<br>
        &nbsp;|&nbsp;'&nbsp;//&nbsp;__|/&nbsp;_`&nbsp;|&nbsp;'_&nbsp;\&nbsp;/&nbsp;_`&nbsp;|/&nbsp;_&nbsp;\&nbsp;'__/&nbsp;_&nbsp;\|&nbsp;'_&nbsp;\<br>
        &nbsp;|&nbsp;.&nbsp;\\__&nbsp;\&nbsp;(_|&nbsp;|&nbsp;|&nbsp;|&nbsp;|&nbsp;(_|&nbsp;|&nbsp;&nbsp;__/&nbsp;|&nbsp;|&nbsp;(_)&nbsp;|&nbsp;|&nbsp;|&nbsp;|<br>
        &nbsp;|_|\_\___/\__,_|_|&nbsp;|_|\__,_|\___|_|&nbsp;&nbsp;\___/|_|&nbsp;|_|
    </div>
        <?php
            function dirToMenu($dir)
            {
                $result = "";
                $cdir = scandir($dir);
                foreach($cdir as $value)
                {
                    if(!in_array($value,array(".","..")))
                    {
                        if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
                        {
                            $result .= "\n<li>" . $value . "\n<ul>" . dirToMenu($dir . DIRECTORY_SEPARATOR . $value) . "\n</ul>\n</li>";
                        }
                        else
                        {
                            $result .= "\n<li> <a href='index.php?document=" . base64_encode($dir . DIRECTORY_SEPARATOR . $value) . "'>" . $value . "</a></li>";
                        }
                    }
                }
                return $result;
            }
            echo "\n<ul class='menu'>" . dirToMenu("documents") . "\n</ul>\n\n";
        ?>
    <div class="content">
        <?php
            $document = base64_decode($_GET['document']);
            $vroot = realpath(getcwd());
            if($document == null)
            {
                echo file_get_contents("index");
            }
            else if(substr(realpath($document), 0, strlen($vroot)) != $vroot or is_dir($document))
            {
                echo file_get_contents("badRequest");
            }
            else
            {
               echo file_get_contents($document);
            }
        ?>
    </div>
    
    <div class="footer">
    ksanderon@net:~/$ sed 's/unknown/known/g'<span class="blink">_</span>
    </div>
</body>
</html>
